package com.gla.Controller;

import com.gla.result.Result;
import com.gla.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("wallet")
public class WalletController {

    @Autowired
    WalletService walletService;

    @GetMapping("/getMoney/{user_id}")
    public Result getMoney(@PathVariable Integer user_id){
        Double money = walletService.getMoney(user_id);
        return Result.succeed(money);
    }

    @GetMapping("/update")
    public Result update(Integer user_id, Double number){
        Integer code =walletService.update(user_id, number);
        if(code == -1) {
            return Result.fail("余额不足，请充值!");
        } else if(code == -2){
            return Result.fail("用户不存在,无法查询余额!");
        }
        return Result.succeed("成功!");
    }
}
